package logic

import (
	"context"
	"course_srv/models/mysql"

	"course_srv/course"
	"course_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CourseListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCourseListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CourseListLogic {
	return &CourseListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CourseListLogic) CourseList(in *course.CourseListRequest) (*course.CourseListResponse, error) {
	c := mysql.Course{}
	list, _ := c.CourseList()
	var slice []*course.CourseList
	for _, v := range list {
		slice = append(slice, &course.CourseList{
			Id:      int32(v.ID),
			Name:    v.Name,
			Teacher: v.Teacher,
			Intro:   v.Intro,
			Price:   float32(v.Price),
			Cover:   v.Cover,
			Video:   v.Video,
		})
	}
	return &course.CourseListResponse{List: slice}, nil
}
